package com.wc.算法基础课.C第三讲搜索与图论.DFS.木棒;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/3/14 22:05
 * @description https://www.acwing.com/problem/content/169/
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 70;
    static int[] sticks = new int[N];
    static boolean[] st = new boolean[N];
    static int sum = 0, length = 0;
    static int n;

    public static void main(String[] args) {
        while (true) {
            n = sc.nextInt();
            if (n == 0) break;
            sum = length = 0;

            for (int i = 0; i < n; i++) {
                int l = sc.nextInt();
                sticks[i] = l;
                sum += l;
                length = Math.max(l, length);
            }
            Arrays.sort(sticks, 0, n);
            for (int i = 0, j = n - 1; i < j; i++, j--) {
                int tmp = sticks[i];
                sticks[i] = sticks[j];
                sticks[j] = tmp;
            }
            while (true) {
                if (sum % length == 0 && dfs(0, 0, 0)) {
                    out.println(length);
                    break;
                }
                length++;
            }
            Arrays.fill(st, 0, n, false);
        }
        out.flush();
    }

    /**
     * 深度遍历
     *
     * @param u     遍历到第几根了
     * @param cur   当前长度
     * @param start 当前开始坐标， 保证拼接的编号是从小到大的
     * @return 是否满足了
     */
    static boolean dfs(int u, int cur, int start) {
        if (u * length == sum) return true;
        if (cur == length) return dfs(u + 1, 0, 0);

        for (int i = start; i < n; i++) {
            if (st[i]) continue;
            int l = sticks[i];
            if (l + cur <= length) {
                st[i] = true;
                if (dfs(u, cur + l, i + 1)) return true;
                st[i] = false;
            }
            // 第一个棍子就不满足
            if (cur == 0) return false;
            // 最后一个棍子不满足
            if (cur + l == length) return false;
            // 去除重复的
            int j = i + 1;
            while (j < n && sticks[j] == l) j++;
            // 抵抗最上面的i++
            i = j - 1;
        }

        return false;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
